package com.airplane.auto.service;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

import com.airplane.auto.util.ConfigCenter;
import com.airplane.auto.util.Constants;

public class MyNotification extends BroadcastReceiver{
	
	@Override
	public void onReceive(Context context, Intent intent) {
		
	     //执行方法体，实现业务逻辑
		if(ConfigCenter.getValue(context, Constants.ENABLE_AUTO_CHANGE, true)){	
			
			boolean state = intent.getBooleanExtra("state", true);			
			
			changeAirPlaneMode(context,state);
		}
	}
	
	
	
	private void changeAirPlaneMode(Context mContext, boolean enabling){
   	 // Change the system setting
       Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 
                               enabling ? 1 : 0);
       
       // Post the intent
       Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
       intent.putExtra("state", enabling);
       mContext.sendBroadcast(intent);
       
//       Settings.System.AIRPLANE_MODE_RADIOS
//       public static final String RADIO_BLUETOOTH = "bluetooth";
//    	   public static final String RADIO_CELL = "cell";
//    	   public static final String RADIO_WIFI = "wifi"
//       存储的格式 airplane_mode_radios|cell,bluetooth,wifi
    		   
       
   }
	

}
